/**
 *
 */
package ua.at.tsvetkov.samizdat.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import ua.at.tsvetkov.samizdat.R;
import ua.at.tsvetkov.samizdat.data.Data;
import ua.at.tsvetkov.samizdat.data.DataDownloader;

/**
 * @author A.Tsvetkov 2011, http://tsvetkov.at.ua, al@ukr.net Адаптер основного меню.
 */
public class AdtAcAlphabet extends BaseAdapter {

	private LayoutInflater	mInflater;
	private DataDownloader	alphabetDownloader;

	public AdtAcAlphabet(Context context, DataDownloader alphabetDownloader) {
		this.mInflater = LayoutInflater.from(context);
		this.alphabetDownloader = alphabetDownloader;
	}

	/*
	 * (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		return alphabetDownloader.size();
	}

	/*
	 * (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		AlphabetViewHolder holder = new AlphabetViewHolder();
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.adt_alphabet, null);
			holder.menuText = (TextView) convertView.findViewById(R.id.AdtAcAlphabetText);
			holder.countText = (TextView) convertView.findViewById(R.id.AdtAcAlphabetCount);
			convertView.setTag(holder);
		} else {
			holder = (AlphabetViewHolder) convertView.getTag();
		}

		String[] data = alphabetDownloader.getDataFields(position, Data.ALPHABET_FIELDS_COUNT);
		holder.menuText.setText(data[Data.ALPHABET_TEXT]);
		holder.countText.setText(data[Data.ALPHABET_COUNT]);
		return convertView;
	}

}

class AlphabetViewHolder {
	TextView	menuText;
	TextView	countText;
}
